package com.wechat.admin.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * @Author:sjb
 * @CreateTime:2024-12-15
 * @Description: 允许匿名访问切面类
 * @Version：1.0
 */
@Component
@Aspect
@Slf4j
public class AnonymousAccessAspect {

    @Before("@annotation(com.wechat.admin.annoation.AnonymousAccess) || @within(com.wechat.admin.annoation.AnonymousAccess)")
    public void allowAnonymousAccess() {
        // 清除当前线程的认证信息，允许匿名访问
        SecurityContextHolder.clearContext();
        log.info("Anonymous access allowed for the current endpoint.");
    }
}
